//
//  UserUseListModel.m
//
//  Created by  殷聃 on 2019/7/24
//  Copyright (c) 2019 yek. All rights reserved.
//

#import "UserUseListModel.h"


NSString *const kUserUseListModelId = @"id";
NSString *const kUserUseListModelUseWeight = @"useWeight";
NSString *const kUserUseListModelUseTimeLength = @"useTimeLength";
NSString *const kUserUseListModelUseMood = @"useMood";
NSString *const kUserUseListModelDelete = @"delete";
NSString *const kUserUseListModelUserId = @"userId";
NSString *const kUserUseListModelUseTime = @"useTime";
NSString *const kUserUseListModelMenstruation = @"menstruation";
NSString *const kUserUseListModelAddTime = @"addTime";
NSString *const kUserUseListModelUsePicture = @"usePicture";
NSString *const kUserUseListModelUseFeel = @"useFeel";
NSString *const kUserUseListModelHasImage = @"hasImage";


@interface UserUseListModel ()

- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict;

@end

@implementation UserUseListModel

@synthesize internalBaseClassIdentifier = _internalBaseClassIdentifier;
@synthesize useWeight = _useWeight;
@synthesize useTimeLength = _useTimeLength;
@synthesize useMood = _useMood;
@synthesize delete = _delete;
@synthesize userId = _userId;
@synthesize useTime = _useTime;
@synthesize menstruation = _menstruation;
@synthesize addTime = _addTime;
@synthesize usePicture = _usePicture;
@synthesize useFeel = _useFeel;
@synthesize hasImage = _hasImage;


+ (instancetype)modelObjectWithDictionary:(NSDictionary *)dict
{
    return [[self alloc] initWithDictionary:dict];
}

- (instancetype)initWithDictionary:(NSDictionary *)dict
{
    self = [super init];
    
    // This check serves to make sure that a non-NSDictionary object
    // passed into the model class doesn't break the parsing.
    if(self && [dict isKindOfClass:[NSDictionary class]]) {
            self.internalBaseClassIdentifier = [[self objectOrNilForKey:kUserUseListModelId fromDictionary:dict] doubleValue];
            self.useWeight = [self objectOrNilForKey:kUserUseListModelUseWeight fromDictionary:dict];
            self.useTimeLength = [[self objectOrNilForKey:kUserUseListModelUseTimeLength fromDictionary:dict] doubleValue];
            self.useMood = [self objectOrNilForKey:kUserUseListModelUseMood fromDictionary:dict];
            self.delete = [[self objectOrNilForKey:kUserUseListModelDelete fromDictionary:dict] boolValue];
            self.userId = [self objectOrNilForKey:kUserUseListModelUserId fromDictionary:dict];
            self.useTime = [[self objectOrNilForKey:kUserUseListModelUseTime fromDictionary:dict] doubleValue];
            self.menstruation = [self objectOrNilForKey:kUserUseListModelMenstruation fromDictionary:dict];
            self.addTime = [[self objectOrNilForKey:kUserUseListModelAddTime fromDictionary:dict] doubleValue];
            self.usePicture = [self objectOrNilForKey:kUserUseListModelUsePicture fromDictionary:dict];
            self.useFeel = [self objectOrNilForKey:kUserUseListModelUseFeel fromDictionary:dict];
            self.hasImage = [[self objectOrNilForKey:kUserUseListModelHasImage fromDictionary:dict] boolValue];

    }
    
    return self;
    
}

- (NSDictionary *)dictionaryRepresentation
{
    NSMutableDictionary *mutableDict = [NSMutableDictionary dictionary];
    [mutableDict setValue:[NSNumber numberWithDouble:self.internalBaseClassIdentifier] forKey:kUserUseListModelId];
    [mutableDict setValue:self.useWeight forKey:kUserUseListModelUseWeight];
    [mutableDict setValue:[NSNumber numberWithDouble:self.useTimeLength] forKey:kUserUseListModelUseTimeLength];
    [mutableDict setValue:self.useMood forKey:kUserUseListModelUseMood];
    [mutableDict setValue:[NSNumber numberWithBool:self.delete] forKey:kUserUseListModelDelete];
    [mutableDict setValue:self.userId forKey:kUserUseListModelUserId];
    [mutableDict setValue:[NSNumber numberWithDouble:self.useTime] forKey:kUserUseListModelUseTime];
    [mutableDict setValue:self.menstruation forKey:kUserUseListModelMenstruation];
    [mutableDict setValue:[NSNumber numberWithDouble:self.addTime] forKey:kUserUseListModelAddTime];
    [mutableDict setValue:self.usePicture forKey:kUserUseListModelUsePicture];
    [mutableDict setValue:self.useFeel forKey:kUserUseListModelUseFeel];
    [mutableDict setValue:[NSNumber numberWithBool:self.hasImage] forKey:kUserUseListModelHasImage];

    return [NSDictionary dictionaryWithDictionary:mutableDict];
}

- (NSString *)description 
{
    return [NSString stringWithFormat:@"%@", [self dictionaryRepresentation]];
}

#pragma mark - Helper Method
- (id)objectOrNilForKey:(id)aKey fromDictionary:(NSDictionary *)dict
{
    id object = [dict objectForKey:aKey];
    return [object isEqual:[NSNull null]] ? nil : object;
}


#pragma mark - NSCoding Methods

- (id)initWithCoder:(NSCoder *)aDecoder
{
    self = [super init];

    self.internalBaseClassIdentifier = [aDecoder decodeDoubleForKey:kUserUseListModelId];
    self.useWeight = [aDecoder decodeObjectForKey:kUserUseListModelUseWeight];
    self.useTimeLength = [aDecoder decodeDoubleForKey:kUserUseListModelUseTimeLength];
    self.useMood = [aDecoder decodeObjectForKey:kUserUseListModelUseMood];
    self.delete = [aDecoder decodeBoolForKey:kUserUseListModelDelete];
    self.userId = [aDecoder decodeObjectForKey:kUserUseListModelUserId];
    self.useTime = [aDecoder decodeDoubleForKey:kUserUseListModelUseTime];
    self.menstruation = [aDecoder decodeObjectForKey:kUserUseListModelMenstruation];
    self.addTime = [aDecoder decodeDoubleForKey:kUserUseListModelAddTime];
    self.usePicture = [aDecoder decodeObjectForKey:kUserUseListModelUsePicture];
    self.useFeel = [aDecoder decodeObjectForKey:kUserUseListModelUseFeel];
    self.hasImage = [aDecoder decodeBoolForKey:kUserUseListModelHasImage];
    return self;
}

- (void)encodeWithCoder:(NSCoder *)aCoder
{

    [aCoder encodeDouble:_internalBaseClassIdentifier forKey:kUserUseListModelId];
    [aCoder encodeObject:_useWeight forKey:kUserUseListModelUseWeight];
    [aCoder encodeDouble:_useTimeLength forKey:kUserUseListModelUseTimeLength];
    [aCoder encodeObject:_useMood forKey:kUserUseListModelUseMood];
    [aCoder encodeBool:_delete forKey:kUserUseListModelDelete];
    [aCoder encodeObject:_userId forKey:kUserUseListModelUserId];
    [aCoder encodeDouble:_useTime forKey:kUserUseListModelUseTime];
    [aCoder encodeObject:_menstruation forKey:kUserUseListModelMenstruation];
    [aCoder encodeDouble:_addTime forKey:kUserUseListModelAddTime];
    [aCoder encodeObject:_usePicture forKey:kUserUseListModelUsePicture];
    [aCoder encodeObject:_useFeel forKey:kUserUseListModelUseFeel];
    [aCoder encodeBool:_hasImage forKey:kUserUseListModelHasImage];
}

- (id)copyWithZone:(NSZone *)zone
{
    UserUseListModel *copy = [[UserUseListModel alloc] init];
    
    if (copy) {

        copy.internalBaseClassIdentifier = self.internalBaseClassIdentifier;
        copy.useWeight = [self.useWeight copyWithZone:zone];
        copy.useTimeLength = self.useTimeLength;
        copy.useMood = [self.useMood copyWithZone:zone];
        copy.delete = self.delete;
        copy.userId = [self.userId copyWithZone:zone];
        copy.useTime = self.useTime;
        copy.menstruation = [self.menstruation copyWithZone:zone];
        copy.addTime = self.addTime;
        copy.usePicture = [self.usePicture copyWithZone:zone];
        copy.useFeel = [self.useFeel copyWithZone:zone];
        copy.hasImage = self.hasImage;
    }
    
    return copy;
}


@end
